<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: relative;
            left: 0;
            top: 0;
            width: 200px;
            height: 200px;
            border: 1px solid #000;
            background-color: pink;
        }
    </style>
</head>

<body>


    <div></div>
    <hr>
    <button class="btn">动起来</button>
    <script>
        var div = document.querySelector('div')
        var btn = document.querySelector('.btn')
        var timer = setInterval(function() {
            var step = 10
            var currentPosition = div.offsetLeft
            if (currentPosition < 800) {
                currentPosition += step
                div.style.left = currentPosition + 'px'
            } else {
                clearInterval(timer)
            }
        }, 15)
    </script>
</body>

</html>